<template>
	<xn-form-container
		:title="formData.wordrank ? '编辑4级单词表' : '增加4级单词表'"
		:width="700"
		v-model:open="open"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
			<a-form-item label="BOOKID：" name="bookid">
				<a-input v-model:value="formData.bookid" placeholder="请输入BOOKID" allow-clear />
			</a-form-item>
			<a-form-item label="STATUS：" name="status">
				<a-input v-model:value="formData.status" placeholder="请输入STATUS" allow-clear />
			</a-form-item>
			<a-form-item label="HEADWORD：" name="headword">
				<a-input v-model:value="formData.headword" placeholder="请输入HEADWORD" allow-clear />
			</a-form-item>
			<a-form-item label="USPHONE：" name="usphone">
				<a-input v-model:value="formData.usphone" placeholder="请输入USPHONE" allow-clear />
			</a-form-item>
			<a-form-item label="UKPHONE：" name="ukphone">
				<a-input v-model:value="formData.ukphone" placeholder="请输入UKPHONE" allow-clear />
			</a-form-item>
			<a-form-item label="UKSPEECH：" name="ukspeech">
				<a-input v-model:value="formData.ukspeech" placeholder="请输入UKSPEECH" allow-clear />
			</a-form-item>
			<a-form-item label="USSPEECH：" name="usspeech">
				<a-input v-model:value="formData.usspeech" placeholder="请输入USSPEECH" allow-clear />
			</a-form-item>
			<a-form-item label="TRANCN：" name="trancn">
				<a-input v-model:value="formData.trancn" placeholder="请输入TRANCN" allow-clear />
			</a-form-item>
			<a-form-item label="POS：" name="pos">
				<a-input v-model:value="formData.pos" placeholder="请输入POS" allow-clear />
			</a-form-item>
			<a-form-item label="TRANOTHER：" name="tranother">
				<a-input v-model:value="formData.tranother" placeholder="请输入TRANOTHER" allow-clear />
			</a-form-item>
			<a-form-item label="QUESTION：" name="question">
				<a-input v-model:value="formData.question" placeholder="请输入QUESTION" allow-clear />
			</a-form-item>
			<a-form-item label="EXPLAIN：" name="explain">
				<a-input v-model:value="formData.explain" placeholder="请输入EXPLAIN" allow-clear />
			</a-form-item>
			<a-form-item label="RIGHTINDEX：" name="rightindex">
				<a-input v-model:value="formData.rightindex" placeholder="请输入RIGHTINDEX" allow-clear />
			</a-form-item>
			<a-form-item label="EXAMTYPE：" name="examtype">
				<a-input v-model:value="formData.examtype" placeholder="请输入EXAMTYPE" allow-clear />
			</a-form-item>
			<a-form-item label="CHOICEINDEXONE：" name="choiceindexone">
				<a-input v-model:value="formData.choiceindexone" placeholder="请输入CHOICEINDEXONE" allow-clear />
			</a-form-item>
			<a-form-item label="CHOICEINDEXTWO：" name="choiceindextwo">
				<a-input v-model:value="formData.choiceindextwo" placeholder="请输入CHOICEINDEXTWO" allow-clear />
			</a-form-item>
			<a-form-item label="CHOICEINDEXTHREE：" name="choiceindexthree">
				<a-input v-model:value="formData.choiceindexthree" placeholder="请输入CHOICEINDEXTHREE" allow-clear />
			</a-form-item>
			<a-form-item label="CHOICEINDEXFOUR：" name="choiceindexfour">
				<a-input v-model:value="formData.choiceindexfour" placeholder="请输入CHOICEINDEXFOUR" allow-clear />
			</a-form-item>
			<a-form-item label="SENTENCE：" name="sentence">
				<a-input v-model:value="formData.sentence" placeholder="请输入SENTENCE" allow-clear />
			</a-form-item>
			<a-form-item label="SENTENCECN：" name="sentencecn">
				<a-input v-model:value="formData.sentencecn" placeholder="请输入SENTENCECN" allow-clear />
			</a-form-item>
			<a-form-item label="PHRASE：" name="phrase">
				<a-input v-model:value="formData.phrase" placeholder="请输入PHRASE" allow-clear />
			</a-form-item>
			<a-form-item label="PHRASECN：" name="phrasecn">
				<a-input v-model:value="formData.phrasecn" placeholder="请输入PHRASECN" allow-clear />
			</a-form-item>
			<a-form-item label="DIFFICULTY：" name="difficulty">
				<a-input v-model:value="formData.difficulty" placeholder="请输入DIFFICULTY" allow-clear />
			</a-form-item>
			<a-form-item label="DAYSBETWEENREVIEWS：" name="daysbetweenreviews">
				<a-input v-model:value="formData.daysbetweenreviews" placeholder="请输入DAYSBETWEENREVIEWS" allow-clear />
			</a-form-item>
			<a-form-item label="LASTSCORE：" name="lastscore">
				<a-input v-model:value="formData.lastscore" placeholder="请输入LASTSCORE" allow-clear />
			</a-form-item>
			<a-form-item label="DATELASTREVIEWED：" name="datelastreviewed">
				<a-date-picker v-model:value="formData.datelastreviewed" value-format="YYYY-MM-DD HH:mm:ss" show-time placeholder="请选择DATELASTREVIEWED" style="width: 100%" />
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
			<a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
		</template>
	</xn-form-container>
</template>

<script setup name="bizCet43Form">
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	import bizCet43Api from '@/api/biz/bizCet43Api'
	// 抽屉状态
	const open = ref(false)
	const emit = defineEmits({ successful: null })
	const formRef = ref()
	// 表单数据
	const formData = ref({})
	const submitLoading = ref(false)

	// 打开抽屉
	const onOpen = (record) => {
		open.value = true
		if (record) {
			let recordData = cloneDeep(record)
			formData.value = Object.assign({}, recordData)
		}
	}
	// 关闭抽屉
	const onClose = () => {
		formRef.value.resetFields()
		formData.value = {}
		open.value = false
	}
	// 默认要校验的
	const formRules = {
	}
	// 验证并提交数据
	const onSubmit = () => {
		formRef.value
			.validate()
			.then(() => {
				submitLoading.value = true
				const formDataParam = cloneDeep(formData.value)
				bizCet43Api
					.bizCet43SubmitForm(formDataParam, formDataParam.wordrank)
					.then(() => {
						onClose()
						emit('successful')
					})
					.finally(() => {
						submitLoading.value = false
					})
			})
			.catch(() => {})
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
